package com.design.yjx.state;

import java.util.Random;

/**
 * @author yuanjianxin
 * @date 2017/8/23 16:31
 */
public class HasQuarterState implements State {

    Random random = new Random();

    private GumballMachine gumballMachine;

    public HasQuarterState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    @Override
    public void ejectQuarter() {
        System.out.println("退钱");
        gumballMachine.setState(gumballMachine.getNoQuarterState());
    }

    @Override
    public void turnCrank() {
        System.out.println("转动手柄");
        int i = random.nextInt(10);
        if (i == 0) {
            gumballMachine.setState(gumballMachine.getWinnerState());
        }else{
            gumballMachine.setState(gumballMachine.getSoldState());
        }
    }
}
